<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const template = function fn(id, obj) {
            let html = document.querySelector('#' + id).innerHTML
            let reg = /{{(\w+)}}/g
            let res = html.replace(reg, function (...args) {
                return obj[args[1]]
            })
        }
        // 示例
        let str =
            `
        <p>{{uname}}</p>
        <p>{{age}}</p>
        `
        let data = {
            uname: '大酋长',
            age: 70
        }
        let reg = /{{(\w+)}}/g
        let res = str.replace(reg, function (...args) {
            console.log(args);
            return data[args[1]]
        })
        // console.log(res);
        document.querySelector('#box').innerHTML = res
    </script>
</body>

</html>